package com.example.administrator.x3picturetransliteration.Home.Presenter.Activity;

import android.content.Context;

import com.example.administrator.x3picturetransliteration.Base.BasePresenter;
import com.example.administrator.x3picturetransliteration.Base.HttpGo;
import com.example.administrator.x3picturetransliteration.Bean.HttpDataBean;

import java.util.Map;

import rx.subscriptions.CompositeSubscription;

/**
 * 翻译
 * Created by Administrator on 2019/9/4.
 */

public class TranslatePresenter extends BasePresenter{

    public TranslatePresenter(Context context, CompositeSubscription mCompositeSubscription) {
        super(context, mCompositeSubscription);
    }

    /** 翻译 */
    public void ots(Map<String,String>httpdata, final Callback mCallback){

        mCompositeSubscription.add(

                mHttpGo.postSubscription("xfyun/ots", httpdata, new HttpGo.HttpGoCallback() {
                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(HttpDataBean httpDataBean) {

                        if (httpDataBean.getCode()==0){

                            if (httpDataBean.getData()==null)return;

                            Map<String,Object> map = (Map<String,Object>)httpDataBean.getData();

                            Map<String,String> data = (Map<String,String>)map.get("trans_result");

                            if (data.get("dst")!=null)mCallback.getData(data.get("dst"));
                        }
                    }
                })
        );

    }

    /** 保存文档 */
    public void addwork(Map<String,String> httpdata, final Callback mCallback){

        mCompositeSubscription.add(

                mHttpGo.postSubscription("user_works/add", httpdata, new HttpGo.HttpGoCallback() {
                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(HttpDataBean httpDataBean) {

                        if (httpDataBean.getCode()==0)mCallback.getData(httpDataBean.getData());
                    }
                })
        );
    }

    /** 导出文档 */
    public void export(Map<String,String> httpdata, final Callback mCallback){

        mCompositeSubscription.add(

                mHttpGo.postSubscription("user_works/export", httpdata, null,new HttpGo.HttpGoCallback() {
                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(HttpDataBean httpDataBean) {

                        if (httpDataBean.getCode()==0){

                            if (httpDataBean.getData()!=null)mCallback.getData(httpDataBean.getData());
                        }
                    }
                })
        );

    }
}
